<?php
/**
 * *********************************************************************************************************************
 * 安能派件清单
 * *********************************************************************************************************************
 */
namespace soa\partner\ane;


use soa\partner\partnerCommon;

class Delivery extends AneClient
{
    /**
     * 请求超时时间
     *
     * @var int
     */
    protected $_timeout = 10;

    /**
     * @param $siteId
     * @param string $mobile
     * @param $beginDate
     * @param $endDate
     * @return array
     */
    public function getDeliveryList($siteId, $mobile, $beginDate, $endDate)
    {
        $beginDate = $beginDate ? date('Y-m-d', strtotime($beginDate)) : date('Y-m-d',strtotime('-1 day'));
        $endDate = $endDate ? date('Y-m-d', strtotime($endDate)) : date('Y-m-d');

        $accessInfo = partnerCommon::getAccessInfo(['brand'=>'ane','username'=>$mobile]);
        if(empty($accessInfo['3rd_party_id']) || empty($accessInfo['3rd_branch_id'])){
            raise(1009);
        }

        $time1 = time();

        $result = $this->send('deliveryListService', [
            'deliveryManId' => $accessInfo['3rd_party_id'],
            'siteId'        => $accessInfo['3rd_branch_id'],
            'startTime'     => $beginDate,
            'endTime'       => $endDate,
        ]);

        $return = [
            'billCodes' => [],
            'billInfos' => [],
        ];

        if($result && is_array($result)){
            foreach($result as $item){
                if(empty($item['ewbNo'])){
                    continue;
                }

                $return['billCodes'][] = $item['ewbNo'];
                $return['billInfos'][$item['ewbNo']] = [
                    'billCode' => $item['ewbNo'],
                    'scanTime' => date('Y-m-d H:i:s',substr($item['scanTime'],0,10)),
                ];
            }
        }
        logDebug(count($return['billCodes']).' '.count($return['billInfos']) . ' 工号:' . $accessInfo['3rd_party_id'] . '网点：' . $accessInfo['3rd_branch_id'], 'ane_delivery', $mobile . '-' .(time()-$time1));
        return $return;
    }
}